package com.hqd.jjvm.classformat.constantpool;

import com.hqd.jjvm.classformat.ClassFile;
import com.hqd.jjvm.util.HexStrTransformUtil;
import lombok.Getter;

/**
 * 引用常量池
 */
@Getter
public class ConstantRef extends ConstantPool {
	/**
	 * 常量的索引
	 */
	private Integer classIndex;
	private Integer nameAndTypeIndex;

	public ConstantRef(ConstantInfoType tag, ClassFile classFile) {
		super(tag, classFile);
		this.classIndex = HexStrTransformUtil.parseHexToInt(classFile.readU2());
		checkPoolIndex(classIndex);
		this.nameAndTypeIndex = HexStrTransformUtil.parseHexToInt(classFile.readU2());
		checkPoolIndex(nameAndTypeIndex);
	}

	@Override
	public Object getVal() {
		return this;
	}
}
